<%@page contentType="text/html;charset=UTF-8" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">
<%@page import="be.destin.skos.core.SkosManager" %>
<%@page import="be.destin.skos.html.SkosHtmlManager" %>
<%@page import="be.destin.skos.html.SkosHtmlTable" %>
<%@page import="be.destin.skos.html.LocalError" %>
<%@page import="be.destin.skos.core.SchemeInterface" %>
<%@page import="be.destin.skos.core.SchemeUsage" %>
<%@page import="be.destin.skos.core.ConceptScheme" %>
<%@page import="be.destin.skos.core.CollectionScheme" %>
<%@page import="be.destin.skos.core.Predicate" %>
<%@page import="be.destin.skos.core.Profile" %>
<%@page import="be.destin.skos.core.Concept" %>
<%@page import="be.destin.skos.core.Term" %>
<%@page import="be.destin.skos.core.TermFormat" %>
<%@page import="be.destin.skos.core.Url" %>
<%@page import="be.destin.skos.core.Notation" %>
<%@page import="be.destin.skos.core.ReferringApplicationList" %>
<%@page import="be.destin.skos.core.LinkedConcept" %>
<%@page import="be.destin.skos.core.LocalLinkedConcept" %>
<%@page import="be.destin.skos.view.SkosView" %>
<%@page import="be.destin.skos.view.SkosViewType" %>
<%@page import="be.destin.skos.view.SkosViewManager" %>
<%@page import="be.destin.rdf.changes.SkosStatement" %>
<%@page import="be.destin.rdf.changes.Status" %>
<%@page import="be.destin.util.RunCommand" %>
<%@page import="be.destin.util.Util" %>
<%@page import="java.util.List" %>
<%@page import="java.util.Map" %>
<%@page import="java.util.LinkedList" %>
<%@page import="java.util.LinkedHashSet" %>
<%@page import="java.util.HashSet" %>
<%@page import="java.util.TreeMap" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%	 
   SkosHtmlManager skosHtmlManager = SkosHtmlManager.getAskosiSessionInstance(request);
   SkosManager skosManager = skosHtmlManager.getSkosManager();
   String language = skosHtmlManager.getLanguage();
   String conceptCode = request.getParameter("about");
   String independant = request.getParameter("independant");
   String framing = request.getParameter("framed");
   boolean framed = framing != null && framing.equalsIgnoreCase("yes");
   if (independant != null && independant.equalsIgnoreCase("yes")) framed = false;
   framing = "";
   if (framed) framing = "&framed=yes";
   String fixingPage = request.getParameter("fixed");
   boolean fixedPages = fixingPage != null && fixingPage.equalsIgnoreCase("yes");
   if (fixedPages) framing = framing+"&fixed=yes";
   String expanding = request.getParameter("expanded");
   boolean expanded = expanding != null && expanding.equalsIgnoreCase("yes");
   String theProperty = request.getParameter("property");
   String adding = request.getParameter("adding");
   boolean addOnly = adding != null && (adding.equalsIgnoreCase("true")||adding.equalsIgnoreCase("yes"));
   String theLabel = request.getParameter("literal");
   String theLanguage = request.getParameter("literallanguage");
   String theNotation = request.getParameter("notation");
   String linked = request.getParameter("rel");
   String subRel = request.getParameter("relqualifier");
%>
<html>
<head>
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/jqueryui.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/askosi.css" />
<link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/css/ajaxtags.css" />
<title>Concept <%=conceptCode%></title>
	<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <script type="text/javascript" src="js/tablescroll.js"></script>
</head>
<body class="contentpage">
<%
 Concept aConcept = (Concept)skosManager.getScheme_Concept(conceptCode);
 if (aConcept != null) {
        ConceptScheme aScheme = aConcept.getInScheme();	   
	    String statusCode = aConcept.getStatus();
	    if (statusCode == null || statusCode.isEmpty()) statusCode = "";
	    else {
			Concept aStatus = (Concept)skosManager.getScheme_Concept("status_"+statusCode);
			if (aStatus != null) statusCode = skosHtmlManager.toHtmlImage(aStatus.getIconAdapted(skosHtmlManager),aStatus.getAbout(),false);
	    }
		Status currentStatus = aConcept.getCurrentStatus();
		if (currentStatus == null) currentStatus = Status.Published;
		Profile userProfile = skosHtmlManager.getProfileData();
		Predicate aPred = Predicate.find(aConcept,theProperty);
		 Term aTerm = null;
		 Url aUrl = null;
		 LinkedConcept aLink = null	;
		 Object aRelat = null;
		 if (!addOnly) {
			 SkosStatement aStatement = SkosStatement.makeSkosStatement(skosManager,aConcept.stringValue(),theProperty,subRel,TermFormat.REGULAR/*TODO:IMPROVE!*/,theLabel,theLanguage,theNotation,linked);
			 aRelat = aStatement.findExistingRelation(); 
			 if (aRelat != null) {
				 if (aRelat instanceof Term) {
					aTerm = (Term)aRelat;
					currentStatus = aTerm.getCurrentStatus();
					if (currentStatus == null) currentStatus = Status.Published;
				 } else if (aRelat instanceof Url) {
					aUrl = (Url)aRelat;
					currentStatus = aUrl.getCurrentStatus();
					if (currentStatus == null) currentStatus = Status.Published;
				 } else if (aRelat instanceof LinkedConcept)  {
					aLink = (LinkedConcept)aRelat;
					currentStatus = aLink.getCurrentStatus();
					if (currentStatus == null) currentStatus = Status.Published;
				 }
			 }
		 }
	
   if (framed) {
%><script language="JavaScript">
parent.parent.parent.focusFrame(this);
</script><%
   } else {
%><h4><%=statusCode%>Concept <%=skosHtmlManager.toHtmlImage(aConcept.getIconAdapted(skosHtmlManager),aConcept.getAbout(),false)%><span class="math">&#8865;</span><%=aConcept.getAbout()%>
<%
	  if (aConcept.getUrl() != null) {
		for (Url anUrl: aConcept.getUrl()) {
	      %> &nbsp; <a href="<%=anUrl.getValue()%>" target="conceptURL"><span class="language"><%=anUrl.getLang()%></span> <%=anUrl.getValue()%></a> &nbsp; <%
		}
      }
%>
<%if (aConcept.getDepth() > 0) {%>&#8615;<%=aConcept.getDepth()%><%}%>
<span class="math">&isin;</span>
<img src="image/conceptscheme16.gif" border="0"/> <%=skosHtmlManager.toHtmlImage(aScheme.getIconAdapted(skosHtmlManager),aScheme.getAbout(),false)%><a href="view.jsp?scheme=<%=aScheme.getAbout()%><%=framing%>" target="askosi_scheme"><%=aScheme.getAbout()%></a>:
	    <br style="clear:both"/>
     <big style="border:solid 1px; padding:0px 5px 0px 5px;"><img src="image/concept16.gif" border="0"/> <%=aConcept.toHtmlLabel(skosHtmlManager)%></big><a href="<%=aConcept.getAskosiUrl(skosHtmlManager,"&edit=yes")%>"><img<%=skosHtmlManager.askosiIcon("edit")%> border="0"/></a></h4>
<% }%><form method="POST" action="concept.jsp" method="GET">
<input type="hidden" name="concept" value="<%=conceptCode%>"/>
<input type="hidden" name="framed" value="<%=(framed?"yes":"no") %>"/>
<input type="hidden" name="edit" value="yes"/>
<input type="hidden" name="modify" value="yes"/>
<input type="hidden" name="property" value="<%=theProperty%>"/>
<% if (addOnly) {
%><input type="hidden" name="adding" value="yes"/><%
%><%=Status.New_Proposed.toHtml(skosHtmlManager)%><%
	Class objectType = aPred.getObjectClass();
	 if (objectType == Term.class) {
%>Label Text: <input type="radio" name="new_rel" value="prefLabel"<%="prefLabel".equals(theProperty)?" checked":""%>/>pref
<input type="radio" name="new_rel" value="altLabel"<%="altLabel".equals(theProperty)?" checked":""%>/>alt
<input type="radio" name="new_rel" value="hiddenLabel"<%="hiddenLabel".equals(theProperty)?" checked":""%>/>hidden<br/>
<input type="text" name="new_literal" size="64"/><br/>
<input type="radio" name="language" value="en"/>la
<input type="radio" name="language" value="en"/>en
<input type="radio" name="language" value="en"/>fr
<input type="radio" name="language" value="en"/>nl
<input type="radio" name="language" value="en"/>any
<%
	 } else if (objectType == Url.class) {
%>URL:<input type="text" name="new_literal" size="80"/><br/>
[languages menu]<%
	 } else if (objectType == Notation.class) {
%>[menu of allowed notations for this scheme]<br/>
<input type="text" name="new_notation" size="32"/><%
	 } else if (objectType == LinkedConcept.class) {
%>[menu of qualifiers allowed for this relation AND for this scheme]<br/><%
		String[] recentConcepts = SkosHtmlManager.maintainRecentConcepts(request,conceptCode,12);
		if (recentConcepts != null && recentConcepts.length > 0) {
			%><ul><%
			for (int i=recentConcepts.length; i>0; i--) {
				String oneConcept = recentConcepts[i-1];
				if (conceptCode.equals(oneConcept)) continue;
				Concept someConcept = skosManager.getScheme_Concept(oneConcept);
				if (someConcept == null) continue;
				if (!aConcept.getInScheme().equals(someConcept.getInScheme())) {
					%><li><%=someConcept.toHtmlLabel(skosHtmlManager)%></li><%
				}
			}
			%></ul><%
		}
	 } else if (objectType == LocalLinkedConcept.class) {
%>[menu of qualifiers allowed for this relation AND for this scheme]<br/><%
		String[] recentConcepts = SkosHtmlManager.maintainRecentConcepts(request,conceptCode,12);
		if (recentConcepts != null && recentConcepts.length > 0) {
			%><ul><%
			for (int i=recentConcepts.length; i>0; i--) {
				String oneConcept = recentConcepts[i-1];
				if (conceptCode.equals(oneConcept)) continue;
				Concept someConcept = skosManager.getScheme_Concept(oneConcept);
				if (someConcept == null) continue;
				if (aConcept.getInScheme().equals(someConcept.getInScheme())) {
					%><li><%=someConcept.toHtmlLabel(skosHtmlManager)%></li><%
				}
			}
			%></ul><%
		}
	 }
} else {
 if (theLabel != null && !"undefined".equals(theLabel)) {
%>Label Text: <input type="radio" name="rel" value="prefLabel"<%="prefLabel".equals(theProperty)?" checked":""%>/>pref
<input type="radio" name="rel" value="altLabel"<%="altLabel".equals(theProperty)?" checked":""%>/>alt
<input type="radio" name="rel" value="hiddenLabel"<%="hiddenLabel".equals(theProperty)?" checked":""%>/>hidden<br/>
<input type="text" name="literal" size="64" value="<%=theLabel%>"/>
(only minimal changes allowed)
<% }
   if (theLanguage != null && !"undefined".equals(theLanguage)) {
%><input type="radio" name="literallanguage" value="<%=theLanguage%>" checked readonly/><%=theLanguage%><br/>
<% }
   if (theNotation != null && !"undefined".equals(theNotation)) {
%><input type="hidden" name="notation" value="<%=theNotation%>"/>Notation: <%=theNotation%><br/>
<% }
   if (linked != null && !"undefined".equals(linked)) {
%><input type="hidden" name="rel" value="<%=linked%>"/><%=linked%> 
<% }
   if (subRel != null && !"undefined".equals(subRel)) {
%><input type="hidden" name="relqualifier" value="<%=subRel%>"/><%=subRel%> 
<% }
	LinkedList<Status> possibleStatus = aScheme.getPossibleStatus(userProfile,currentStatus,SkosStatement.transitions);
	boolean terse = false;
	for (Status printStatus : possibleStatus) {
		if (printStatus == Status.Change_Proposed || printStatus == Status.Change_Under_Review || printStatus == Status.Deprecated)
		  continue;
		if (printStatus == currentStatus) {
			%><input type="radio" name="status" value="<%=printStatus.toString()%>" checked/><%=printStatus.toHtml(skosHtmlManager)%><strong><%=printStatus.toString()%></strong><br/><%
			terse = true;
		} else {
			%><input type="radio" name="status" value="<%=printStatus.toString()%>"/><%=(terse?"":printStatus.toHtml(skosHtmlManager))%><%=printStatus.toString()%><%=(terse?" &nbsp; ":"<br/>")%><%
		}
	}
%>[menu of other possible relation if Change_Proposed is allowed]<hr noshade/><%
}
%>
<br/>Comment: <textarea rows="3" name="comment" cols="50"></textarea>
<br/><input type="submit" name="go" value=" = "/>
</form>
<%--
<hr noshade/>
	 <table cellspacing="0">
	 <tr><td>Subject</td><td style="text-align:left"><%=SkosStatement.findSkosResource(skosManager,null,aConcept.stringValue())%>
	 <tr><td>Predicate</td><td style="text-align:left"><%=aPred%>
	 <tr><td>Qualifier</td><td style="text-align:left"><%=subRel%>
	 <tr><td>Notation</td><td style="text-align:left"><%=theNotation%>
	 <tr><td>Term</td><td style="text-align:left"><%=aTerm%>
	 <tr><td>Url</td><td style="text-align:left"><%=aUrl%>
	 <tr><td>Relation</td><td style="text-align:left"><%=aLink%>
	 <table>--%>
<% }%>
</body>
</html>